/**
 * 
 */
package name.yzhu.wbdata.io;

import org.apache.log4j.Logger;

import name.yzhu.cloud.CloudException;
import name.yzhu.cloud.hbase.YamlHBaseRowBase;
import name.yzhu.common.lang.DoubleKeyMap;
import name.yzhu.common.yaml.YamlItem;

/**
 * @author yhzhu
 *
 */
public class WeiboYamlRow extends YamlHBaseRowBase {
	private static Logger LOG = Logger.getLogger(WeiboYamlRow.class);
	/**
	 * 
	 */
	private static final long serialVersionUID = -3335641788584968365L;

	/**
	 * 
	 */
	public WeiboYamlRow() {
	}

	/**
	 * @param key
	 */
	public WeiboYamlRow(byte[] key) {
		super(key);
	}

	/**
	 * @param key
	 */
	public WeiboYamlRow(String key) {
		super(key);
	}

	
	public WeiboYamlRow(YamlItem o) {
		super(o);
	}

	@Override
	protected Object byteToObject(String faimly, String key, byte[] value) throws CloudException {
		if (null == key || null == value || value.length == 0)
			return null;
		try {
//			if (key.equals(Constant.YAML_FIELD_WEIBO_CONMENT_COUNT)
//					|| key.equals(Constant.YAML_FIELD_WEIBO_FORWARD_COUNT)
//					|| key.equals(Constant.YAML_FIELD_WEIBO_TIME_LINE)) {
//				    return Bytes.toInt(value);
//			}
//			else 
			    return new String(value, name.yzhu.common.Constant.CHARSET_UTF_8);
		}
		catch (ClassCastException e) {
			LOG.error("key: "+ key+" value: "+String.valueOf(value), e);
			throw new CloudException("key: "+ key+" value: "+String.valueOf(value), e);
		}
	}

	@Override
	protected void read(String key, Object value,
			DoubleKeyMap<String, String, byte[]> row) throws CloudException {
		try{
//			if (key.equals(Constant.YAML_FIELD_WEIBO_CONMENT_COUNT)
//					|| key.equals(Constant.YAML_FIELD_WEIBO_FORWARD_COUNT)
//					|| key.equals(Constant.YAML_FIELD_WEIBO_TIME_LINE))
//				row.put(DEFAULT_FAMILY_NAME, key, Bytes.toBytes((Integer)value));
//			else 
				row.put(DEFAULT_FAMILY_NAME, key, String.valueOf(value).getBytes(name.yzhu.common.Constant.CHARSET_UTF_8));
		}
		catch (ClassCastException e) {
			LOG.error("key: "+ key+" value: "+String.valueOf(value), e);
			throw new CloudException("key: "+ key+" value: "+String.valueOf(value), e);
		}
	}

}
